package com.diandiji.demo.service.impl;

import com.diandiji.demo.dao.UserDao;
import com.diandiji.demo.entity.User;
import com.diandiji.demo.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service // 标识为Spring的Service组件
public class UserServiceImpl implements UserService {

    @Resource // 按名称自动注入UserDao的bean对象
    private UserDao userDao;


    @Override
    public String queryAllUser() {
        List<User> userList = userDao.queryAllUser();
        return userList.toString(); // 返回用户列表的字符串表示;
    }

    @Override
    public User queryUserById(int userID) {
        return userDao.queryUserById(userID);
    }

    @Override
    public User addUser(User user) {
        userDao.addUser(user);
        return user; // 返回添加的用户信息
    }

    @Override
    public User updateUser(User user) {
        userDao.updateUser(user);
        return user; // 返回更新后的用户信息
    }

    @Override
    public void deleteUserByID(int userID) {
        userDao.deleteUserById(userID);
    }

    @Override
    public User findByAccount(String account){
        return userDao.findByAccount(account);
    }

}
